import os
import cv2

def downsample(video_path, output_path):
    video = cv2.VideoCapture(video_path)
    fourcc = cv2.VideoWriter_fourcc('m', 'p', '4', 'v')
    image_width = int(video.get(cv2.CAP_PROP_FRAME_WIDTH))
    image_height = int(video.get(cv2.CAP_PROP_FRAME_HEIGHT))
    fps = video.get(cv2.CAP_PROP_FPS)
    video_writer = cv2.VideoWriter(output_path, fourcc, fps, (int(image_width / 2), int(image_height / 2)))

    while True:
        ret, frame = video.read()
        if ret:
            frame_resized = cv2.resize(frame, (int(image_width / 2), int(image_height / 2)))
            video_writer.write(frame_resized)
        else:
            break
    video_writer.release()



if __name__ == '__main__':
    input_dir = './origin'
    output_dir = './video'
    for video_name in os.listdir(input_dir):
        video_path = os.path.join(input_dir, video_name)
        output_path = os.path.join(output_dir, video_name)
        downsample(video_path, output_path)